package cn.iocoder.yudao.module.infra.api.file;

import cn.iocoder.yudao.module.infra.service.file.FileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * 文件 API 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
@Slf4j
public class FileApiImpl implements FileApi {

    @Resource
    private FileService fileService;

    @Override
    public String createFile(String name, String path, byte[] content) {
        return fileService.createFile(name, path, content);
    }

    @Override
    public byte[] getFileContent(Long configId, String path) throws Exception {
        return fileService.getFileContent(configId, path);
    }

    @Override
    public String getFilePath(Long configId, String path) throws Exception {
        return fileService.getFilePath(configId, path);
    }

    @Override
    public byte[] getFileContent(String id) throws Exception {
        return fileService.getFileContent(id);
    }

    @Override
    public void deleteFile(Long id) throws Exception {
        fileService.deleteFile(id);

    }

    @Override
    public void moveFile(String id, String newPath) {
        try {
            fileService.moveFile(id, newPath);

        } catch (Exception e) {
            log.warn("移动文件失败", e);
        }
    }

    @Override
    public boolean exists(String id) throws Exception {
        return fileService.exists(id);
    }

}
